import request from "@/request";
import { AxiosResponse } from "axios";
import ResultEnum from "@/config/ResultEnum";
import { message } from "ant-design-vue";

export const statusOptions = [
  {
    label: "正常",
    value: "Normal",
    color: "#2db7f5",
  },
  {
    label: "禁用",
    value: "Disable",
    color: "#87d068",
  },
];

export const roleOptions = [
  { label: "User", value: "User" },
  { label: "Member", value: "Member" },
  { label: "Unknow", value: "Unknow" },
];

export const requestMethodOptions = [
  { label: "GET", value: "GET" },
  { label: "POST", value: "POST" },
  { label: "DELETE", value: "DELETE" },
  { label: "PATCH", value: "PATCH" },
  { label: "PUT", value: "PUT" },
];

//表格列
export const tableCols = [
  {
    title: "#",
    dataIndex: "idx",
    key: "idx",
    width: 50,
  },
  {
    title: "ip",
    dataIndex: "ip",
    key: "ip",
  },
  {
    title: "角色",
    dataIndex: "role",
    key: "role",
  },
  {
    title: "Uid",
    dataIndex: "uid",
    key: "uid",
  },
  {
    title: "请求方式",
    dataIndex: "requestMethod",
    key: "requestMethod",
  },
  {
    title: "地址",
    dataIndex: "url",
    key: "url",
  },
  {
    title: "接口",
    dataIndex: "apiName",
    key: "apiName",
  },
  {
    title: "耗时(毫秒)",
    key: "usedTime",
    dataIndex: "usedTime",
  },
  {
    title: "创建时间",
    key: "createdTime",
    dataIndex: "createdTime",
  },
  {
    title: "操作",
    width: "100px",
    key: "actions",
  },
];

//获取数据
export const loadTable = (params: any) => {
  return new Promise((resolve: any, reject: any) => {
    request({
      url: "/requestLog/list",
      method: "get",
      params,
    }).then((res: any) => {
      if (res.code == ResultEnum.SUCCESS_CODE) {
        resolve(res.result);
      } else {
        message.error(res.message);
      }
    });
  });
};
